package com.my12306.train.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.my12306.common.constant.CommonConstants;
import com.my12306.common.model.vo.PageVo;
import com.my12306.common.util.SnowflakeIdWorker;
import com.my12306.train.dao.MarshallingDao;
import com.my12306.train.model.entity.MarshallingEntity;
import com.my12306.train.model.vo.MarshallingCarriageVo;
import com.my12306.train.service.MarshallingService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Service("marshallingService")
public class MarshallingServiceImpl extends ServiceImpl<MarshallingDao, MarshallingEntity> implements MarshallingService {

    @Override
    public List<MarshallingCarriageVo> queryAllMarshallingByParams(PageVo pageVo) {
        pageVo = pageVo.init();
        List<MarshallingCarriageVo> marshallingCarriageVos = this.baseMapper.queryAllMarshalling(pageVo, CommonConstants.LogicDelete.no_delet.getValue());
        System.out.println(marshallingCarriageVos.toString());
        return marshallingCarriageVos;
    }

    @Override
    public MarshallingCarriageVo queryAllMarshallingById(Long id) {
        MarshallingCarriageVo marshallingCarriageVo = this.baseMapper.queryAllMarshallingById(id, CommonConstants.LogicDelete.no_delet.getValue());
        return marshallingCarriageVo;
    }

    @Override
    public Long saveMarshalling(MarshallingEntity marshallingEntity) {
        if(marshallingEntity != null){
            marshallingEntity.setGroupId(SnowflakeIdWorker.generateId());
            marshallingEntity.setCreateDate(new Date());
            marshallingEntity.setUpdateDate(new Date());
            int insert = this.baseMapper.insert(marshallingEntity);
            System.out.println("成功添加编组数：" + insert);
        }
        return null;
    }

    @Override
    public List<MarshallingEntity> queryMarshallingNoMar() {
        QueryWrapper<MarshallingEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("logic_delete",CommonConstants.LogicDelete.no_delet.getValue());
        queryWrapper.eq("mark",0);
        return this.baseMapper.selectList(queryWrapper);
    }
}
